package com.lq.educationsystem.common.util;

import com.lq.educationsystem.common.constant.ResultContant;

import java.util.List;

public class ResultPageBuild {
    //页面成功数据设置

    public static <T> ResultPage pageBuildOk(int page, int pageSize, int countTotal, List<T> data){
        ResultPage resultPage = new ResultPage();
        resultPage.setPageSize(pageSize);
        resultPage.setPage(page);
        resultPage.setData(data);
        resultPage.setCountTotal(countTotal);

        //成功设定
        resultPage.setCode(ResultContant.SUCCESS_RESULT.getCode());
        resultPage.setMessage(ResultContant.SUCCESS_RESULT.getMessage());

        return resultPage;
    }

    public static <T> ResultPage pageBuildOk(ResultPage<T> resultPage, int page, int pageSize, int countTotal, List<T> data){

        resultPage.setPageSize(pageSize);
        resultPage.setPage(page);
        resultPage.setData(data);
        resultPage.setCountTotal(countTotal);

        //获取总页数
        int totalPage = PageUtil.getTotalPage(countTotal, pageSize);
        //设置总页数
        resultPage.setPageTotal(totalPage);
        //设置总数据
        resultPage.setCountTotal(countTotal);


        //成功设定
        resultPage.setCode(ResultContant.SUCCESS_RESULT.getCode());
        resultPage.setMessage(ResultContant.SUCCESS_RESULT.getMessage());

        return resultPage;
    }
    //页面失败数据设置
    public static ResultPage pageBuildDefeat(){
        ResultPage resultPage = new ResultPage();
        resultPage.setCode(ResultContant.DEFEAT_RESULT.getCode());
        resultPage.setMessage(ResultContant.DEFEAT_RESULT.getMessage());

        return resultPage;
    }
    //页面异常数据设置
    public static ResultPage pageBuildError(){
        ResultPage resultPage = new ResultPage();
        resultPage.setCode(ResultContant.ERROR_RESULT.getCode());
        resultPage.setMessage(ResultContant.ERROR_RESULT.getMessage());

        return resultPage;
    }
}
